package com.cbtx.module_sp;

import android.content.Context;
import android.text.TextUtils;

import com.cbtx.module_sp.bean.BaseMachine;
import com.cbtx.module_sp.bean.IMachine;

/**
 * author : joker.peng
 * e-mail : joker@fiture.com
 * date   : 2021/6/10 5:37 PM
 * desc   :
 */
public class MachineFactory {
    private static final String RK3288_PREFIX = "ZLP86Ni";
    private static final String RK3399_PREFIX = "ZLP94Ni";
    private static final String HSV551_PREFIX = "ZLH74Gi";
    private static final String XL983 = "XL983";
    private static final String TXCB88 = "TXCB-88";
    /**
     * userdebug 5.1.1 LMY49F eng.server10.20190815.170525 test
     */
    private static final String ZYSJ_RK3288_CONTAIN = "server10";
    private static IMachine sMachine;

    public static IMachine getAutoCreate(Context context) {
        if (sMachine == null) {
            synchronized (MachineFactory.class) {
                if (sMachine == null) {
                    sMachine = new BaseMachine(context);
                }
            }
        }
        return sMachine;
    }

    /**
     * 判断机型前缀
     *
     * @param model
     * @return
     */
    private static String getPreFix(String model) {
        if (TextUtils.isEmpty(model)) {
            return model;
        }
        if (model.startsWith(RK3288_PREFIX)) {
            return RK3288_PREFIX;
        } else if (model.startsWith(RK3399_PREFIX)) {
            return RK3399_PREFIX;
        } else if (model.startsWith(HSV551_PREFIX)) {
            return HSV551_PREFIX;
        } else if (model.contains(ZYSJ_RK3288_CONTAIN)) {
            return ZYSJ_RK3288_CONTAIN;
        } else if (model.startsWith(XL983) || model.startsWith(TXCB88)) {
            return XL983;
        }
        return model;
    }
}

